package scripts;

import api.AddUserApi;
import api.CommonApi;
import api.LoginApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.uncommons.reportng.HTMLReporter;
import util.AssertUtil;
import util.DBUtil;
import util.ResponseData;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Map;
import java.util.Random;
@Listeners({HTMLReporter.class})

public class TestUpdateUser {
    private static final Logger logger= LoggerFactory.getLogger(TestAddUser.class);
    private static final CommonApi commonApi=new CommonApi();
    private static final LoginApi loginApi=new LoginApi();
    @BeforeClass
    public static void before() throws IOException, URISyntaxException, IOException, URISyntaxException {
        commonApi.get_verify(String.valueOf(new Random().nextDouble()));
        loginApi.login("admin","12345678","8888");
    }
    private static String get_attach(String Id){
        String sql="SELECT id,pwd_attach from mb_member where id="+ Id;
        Map<String,Object> data= DBUtil.get_one(sql);
        return String.valueOf(data.get("pwd_attach"));
    }
    @Test
    public void test01() throws IOException, URISyntaxException {
        String id="964";
        String pwd="test0001";
        String rePwd="test0001";
        String pwd_attach=this.get_attach(id);
        logger.info("pwd_attach={}",pwd_attach);
        ResponseData responseData = AddUserApi.userPwdUpdate(id, pwd, rePwd, pwd_attach);
        AssertUtil.assertCommon(responseData,200,200,"修改成功");
    }
    @Test
    public static void test02() throws IOException, URISyntaxException {
        String id="0";
        String pwd="test0001";
        String rePwd="test0001";
        String pwd_attach=get_attach(id);
        logger.info("pwd_attach={}",pwd_attach);
        ResponseData responseData = AddUserApi.userPwdUpdate(id, pwd, rePwd, pwd_attach);
        AssertUtil.assertCommon(responseData,200,100,"");
    }@Test
    public static void test03() throws IOException, URISyntaxException {
        String id="964";
        String pwd="0001";
        String rePwd="0001";
        String pwd_attach=get_attach(id);
        logger.info("pwd_attach={}",pwd_attach);
        ResponseData responseData = AddUserApi.userPwdUpdate(id, pwd, rePwd, pwd_attach);
        AssertUtil.assertCommon(responseData,200,100,"密码长度6~16之间且密码为英文、数字的组合");
    }@Test
    public static void test04() throws IOException, URISyntaxException {
        String id="964";
        String pwd="test0001";
        String rePwd="test000";
        String pwd_attach=get_attach(id);
        logger.info("pwd_attach={}",pwd_attach);
        ResponseData responseData = AddUserApi.userPwdUpdate(id, pwd, rePwd, pwd_attach);
        AssertUtil.assertCommon(responseData,200,100,"两次输入的密码不一致");
    }@Test
    public static void test05() throws IOException, URISyntaxException {
        String id="964";
        String pwd="test0001";
        String rePwd="test0001";
        String pwd_attach="wdwdw";
        logger.info("pwd_attach={}",pwd_attach);
        ResponseData responseData = AddUserApi.userPwdUpdate(id, pwd, rePwd, pwd_attach);
        AssertUtil.assertCommon(responseData,200,100,"");
    }@Test
    public void test06() throws IOException, URISyntaxException {
        String id="";
        String pwd="test0001";
        String rePwd="test0001";
        String pwd_attach=this.get_attach(id);
        logger.info("pwd_attach={}",pwd_attach);
        ResponseData responseData = AddUserApi.userPwdUpdate(id, pwd, rePwd, pwd_attach);
        AssertUtil.assertCommon(responseData,200,100,"");
    }@Test
    public static void test07() throws IOException, URISyntaxException {
        String id="964";
        String pwd="";
        String rePwd="";
        String pwd_attach=get_attach(id);
        logger.info("pwd_attach={}",pwd_attach);
        ResponseData responseData = AddUserApi.userPwdUpdate(id, pwd, rePwd, pwd_attach);
        AssertUtil.assertCommon(responseData,200,100,"登陆密码不能为空");
    }@Test
    public static void test08() throws IOException, URISyntaxException {
        String id="964";
        String pwd="test0001";
        String rePwd="test0001";
        String pwd_attach="";
        logger.info("pwd_attach={}",pwd_attach);
        ResponseData responseData = AddUserApi.userPwdUpdate(id, pwd, rePwd, pwd_attach);
        AssertUtil.assertCommon(responseData,200,100,"");
    }

}
